﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using ConsoleWeb;
using JHService;
using TcpService;
using Microsoft.AspNetCore.Hosting;

namespace JHdevice
{
    public class SocketProgram
    {
        public static void Main()
        {
        

            //新建HostBuilder 对象用来注入
            var host = new HostBuilder()
                //添加配置文件
                .ConfigureAppConfiguration((hostContext, configApp) =>
                {
                    configApp.AddJsonFile("appsettings.json", optional: true);//添加配置文件
                })
                //注入类
                .ConfigureServices((hostContext, services) =>
                {
                    ReadServices.ReadSettings(hostContext.Configuration, services);//配置文件注入
                    ReadServices.ReadSocket(services);
                    ReadServices.ReadHttp(services);
                    ReadServices.ReadSqlserver(services);
                    ReadServices.ReadMqtt(services);//MQTT相关的
                }).ConfigureLogging((hostContext, configLogging) =>
                {
                    ReadLogging.Logging(configLogging);//Logging 相关的内容
                })
                .UseConsoleLifetime()
                .Build();
            ServiceLocator.Instance = host.Services;//存储 IServiceProvider 的数据用于后续的注入解耦（为了解决相互依赖的问题）
            ServiceLocator.Instance.GetService<Services>().StartAsync();//启动监听服务
            Console.ReadLine();
        }
    }
}
